package com.central.apps.handler;

import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import com.central.bizcommon.model.flow.FlowNode;
import com.central.bizcommon.model.flow.FlowOpinion;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Slf4j
@Component
public class SrWorkorderHandler extends LvBaseHandler {


    @Autowired
    private HandlerService handlerService;


    @Override
    public void afterExcuteFlow(String app, Long id, FlowNode flowNode, FlowOpinion op, String event) throws Exception {
        if(flowNode.getId().equals("spr")){
            String woeSql = "select sid,wonum from bl_workorder where id="+id;
            log.info("==================sql"+woeSql);
            List<Map<String, Object>> workorderList = handlerService.findBySql(woeSql);
            if(workorderList.size()>0){

                Map Workorder = workorderList.get(0);
                String sid = (String) Workorder.get("sid");
                String wonum = (String) Workorder.get("wonum");
                String sonWoSql = "update bl_serviceapplication set status = '已关闭' where sid='"+sid+"'";
                handlerService.updateBySql(sonWoSql);

            }

        }


    }
}
